import Vue from 'vue';
import Router from 'vue-router';
import _import from './_import';

Vue.use(Router);

/*固定的页面*/
const constantRouterMap = [
  {
    name: 'login',
    path: '/login',
    component: _import('login/index'),
  },
  {
    name: '401',
    path: '/401',
    component: _import('error/401'),
  },
  {
    name: '404',
    path: '/404',
    component: _import('error/404'),
  },
];

const Layout = _import('layout/index');

/**
 * 需要权限的页面路由
 * meta解释,用于权限控制
 * name:页面名
 * menu:对应菜单激活
 * requireAuth: 需要登录才能访问
 * level:需要的权限,数字越大权限越高
 * */
const authRouterMap = [
  {
    name: 'Home',
    path: '/',
    redirect: {name: 'dashboard'},
    component: Layout,
    children: [
      /*首页*/
      {
        name: 'dashboard',
        path: 'dashboard',
        meta: {
          name:'首页',
          menu:'dashboard',
          requireAuth:true,
          level:1,
        },
        component: _import('dashboard/index'),
      },
      /*商品管理-发布商品*/
      {
        name:'goodsPublish',
        path:'goods/publish',
        meta: {
          name:'商品管理-发布商品',
          menu:'goodsPublish',
          requireAuth:true,
          level:1,
        },
        component: _import('goods/publish'),
      },
      /*商品管理-发布商品-快速发布*/
      {
        name:'goodsPublishFast',
        path:'goods/publish/fast',
        meta: {
          name:'商品管理-发布商品-快速发布',
          menu:'goodsPublish',
          requireAuth:true,
          level:1,
        },
        component: _import('goods/publish_fast'),
      },
      /*商品管理-发布商品-普通发布*/
      {
        name:'goodsPublishNormal',
        path:'goods/publish/normal',
        meta: {
          name:'商品管理-发布商品-普通发布',
          menu:'goodsPublish',
          requireAuth:true,
          level:1,
        },
        component: _import('goods/publish_normal'),
      },
      /*商品管理-商品列表*/
      {
        name:'goodsList',
        path:'goods/list',
        meta: {
          name:'商品管理-商品列表',
          menu:'goodsList',
          requireAuth:true,
          level:1,
        },
        component: _import('goods/list'),
      },
      /*商品管理-店铺类目*/
      {
        name:'goodsCategory',
        path:'goods/category',
        meta: {
          name:'商品管理-店铺类目',
          menu:'goodsCategory',
          requireAuth:true,
          level:1,
        },
        component: _import('goods/category'),
      },
      /*订单管理-预约租赁*/
      {
        name:'orderReservation',
        path:'order/reservation',
        meta: {
          name:'订单管理-预约租赁',
          menu:'orderReservation',
          requireAuth:true,
          level:1,
        },
        component: _import('order/reservation'),
      },
      /*订单管理-租赁中*/
      {
        name:'orderLease',
        path:'order/lease',
        meta: {
          name:'订单管理-租赁中',
          menu:'orderLease',
          requireAuth:true,
          level:1,
        },
        component: _import('order/lease'),
      },
      /*订单管理-到期退还*/
      {
        name:'orderReturn',
        path:'order/return',
        meta: {
          name:'订单管理-到期退还',
          menu:'orderReturn',
          requireAuth:true,
          level:1,
        },
        component: _import('order/return'),
      },
      /*订单管理-续租管理*/
      {
        name:'orderRenew',
        path:'order/renew',
        meta: {
          name:'订单管理-续租管理',
          menu:'orderRenew',
          requireAuth:true,
          level:1,
        },
        component: _import('order/renew'),
      },
      /*订单管理-买断管理*/
      {
        name:'orderBuyout',
        path:'order/buyout',
        meta: {
          name:'订单管理-买断管理',
          menu:'orderBuyout',
          requireAuth:true,
          level:1,
        },
        component: _import('order/buyout'),
      },
      /*订单管理-已完成*/
      {
        name:'orderCompleted',
        path:'order/completed',
        meta: {
          name:'订单管理-已完成',
          menu:'orderCompleted',
          requireAuth:true,
          level:1,
        },
        component: _import('order/completed'),
      },
      /*订单管理-已取消*/
      {
        name:'orderCancelled',
        path:'order/cancelled',
        meta: {
          name:'订单管理-已取消',
          menu:'orderCancelled',
          requireAuth:true,
          level:1,
        },
        component: _import('order/cancelled'),
      },
      /*订单管理-订单详情*/
      {
        name:'orderInfo',
        path:'order/info',
        meta: {
          name:'订单管理-订单详情',
          menu:'orderInfo',
          requireAuth:true,
          level:1,
        },
        component: _import('order/info'),
      },
      /*售后管理-维修订单*/
      {
        name:'afterServiceRepair',
        path:'after_service/repair',
        meta: {
          name:'售后管理-维修订单',
          menu:'afterServiceRepair',
          requireAuth:true,
          level:1,
        },
        component: _import('after_service/repair'),
      },
      /*售后管理-退货订单*/
      {
        name:'afterServiceReturn',
        path:'after_service/return',
        meta: {
          name:'售后管理-退货订单',
          menu:'afterServiceReturn',
          requireAuth:true,
          level:1,
        },
        component: _import('after_service/return'),
      },
      /*售后管理-换货订单*/
      {
        name:'afterServiceChange',
        path:'after_service/change',
        meta: {
          name:'售后管理-换货订单',
          menu:'afterServiceChange',
          requireAuth:true,
          level:1,
        },
        component: _import('after_service/change'),
      },
      /*资金管理-我的资产*/
      {
        name:'assetsIndex',
        path:'assets/index',
        meta: {
          name:'资金管理-我的资产',
          menu:'assetsIndex',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/index'),
      },
      /*资金管理-我的资产-提现*/
      {
        name:'assetsWithdraw',
        path:'assets/withdraw',
        meta: {
          name:'资金管理-提现',
          menu:'assetsIndex',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/withdraw'),
      },
      /*资金管理-我的资产-提现规则*/
      {
        name:'assetsWithdrawRule',
        path:'assets/withdraw_rule',
        meta: {
          name:'资金管理-提现规则',
          menu:'assetsIndex',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/withdraw_rule'),
      },
      /*资金管理-我的资产-租金管理*/
      {
        name:'assetsRent',
        path:'assets/rent',
        meta: {
          name:'资金管理-租金管理',
          menu:'assetsRent',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/rent'),
      },
      /*资金管理-我的资产-赔偿金管理*/
      {
        name:'assetsCompensation',
        path:'assets/compensation',
        meta: {
          name:'资金管理-赔偿金管理',
          menu:'assetsCompensation',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/compensation'),
      },
      /*资金管理-我的资产-押金管理*/
      {
        name:'assetsDeposit',
        path:'assets/deposit',
        meta: {
          name:'资金管理-押金管理',
          menu:'assetsDeposit',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/deposit'),
      },
      /*资金管理-我的资产-交易流水*/
      {
        name:'assetsTrading',
        path:'assets/trading',
        meta: {
          name:'资金管理-交易流水',
          menu:'assetsTrading',
          requireAuth:true,
          level:1,
        },
        component: _import('assets/trading'),
      },
      /*客户管理-客户列表*/
      {
        name:'customerList',
        path:'customer/list',
        meta: {
          name:'客户管理-客户列表',
          menu:'customerList',
          requireAuth:true,
          level:1,
        },
        component: _import('customer/list'),
      },
      /*客户管理-客户评论*/
      {
        name:'customerComments',
        path:'customer/comments',
        meta: {
          name:'客户管理-客户评论',
          menu:'customerComments',
          requireAuth:true,
          level:1,
        },
        component: _import('customer/comments'),
      },
      /*客户管理-店铺收藏*/
      {
        name:'customerCollectStore',
        path:'customer/book_store',
        meta: {
          name:'客户管理-店铺收藏',
          menu:'customerCollectStore',
          requireAuth:true,
          level:1,
        },
        component: _import('customer/collect_store'),
      },
      /*客户管理-商品收藏*/
      {
        name:'customerCollectGoods',
        path:'customer/book_goods',
        meta: {
          name:'客户管理-商品收藏',
          menu:'customerCollectGoods',
          requireAuth:true,
          level:1,
        },
        component: _import('customer/collect_goods'),
      },
      /*客户管理-商品收藏-详情*/
      {
        name:'customerCollectGoodsInfo',
        path:'customer/book_goods/info',
        meta: {
          name:'客户管理-商品收藏',
          menu:'customerCollectGoods',
          requireAuth:true,
          level:1,
        },
        component: _import('customer/collect_goods_info'),
      },
      /*账户管理-账号信息*/
      {
        name:'userInfo',
        path:'user/info',
        meta: {
          name:'账户管理-账号信息',
          menu:'userInfo',
          requireAuth:true,
          level:1,
        },
        component: _import('user/info'),
      },
      /*账户管理－店铺信息*/
      {
        name:'storeInfo',
        path:'user/store',
        meta: {
          name:'账户管理-店铺信息',
          menu:'storeInfo',
          requireAuth:true,
          level:1,
        },
        component: _import('user/store'),
      },
      /*账户管理-修改密码*/
      {
        name:'userChangePwd',
        path:'user/change_pwd',
        meta: {
          name:'账户管理-修改密码',
          menu:'userChangePwd',
          requireAuth:true,
          level:1,
        },
        component: _import('user/change_pwd'),
      },
      /*账户管理-地址管理*/
      {
        name:'userAddress',
        path:'user/address',
        meta: {
          name:'账户管理-地址管理',
          menu:'userAddress',
          requireAuth:true,
          level:1,
        },
        component: _import('user/address'),
      },
      /*消息中心*/
      {
        name:'message',
        path:'message',
        meta: {
          name:'消息中心',
          menu:'message',
          requireAuth:true,
          level:1,
        },
        component: _import('message/index'),
      },
      /*富文本测试*/
      {
        name:'editorTest',
        path:'test/editor',
        meta: {
          name:'富文本测试',
          menu:'editorTest',
          requireAuth:true,
          level:1,
        },
        component: _import('test/EditorTest'),
      },
    ]
  },
  /*其他匹配不到跳404*/
  {
    path: '*',
    redirect: {name: '404'},
  }
];

export default new Router({
  mode: 'hash',   // "hash" | "history"
  routes: constantRouterMap.concat(authRouterMap),
});
